$(function() {

	$('.showTrack').on('click', function() {
		popup(this);

		var map = new AMap.Map('showlocation', {
			resizeEnable: true,
			zoom: 11,
			center: [118.57, 24.82]
		});
	});
	$('.delete-list').on('click', function() {
		popup(this, "{:url('delete')}");

	});
	//启用
	$('.startusing').on('click', function() {
		popup(this, "{:url('state')}");

	});
	//禁用
	$('.forbidden').on('click', function() {
		popup(this, "{:url('state')}");

	});
	$('.choose').on('click', function() {
		var index = parent.layer.getFrameIndex(window.name);
		parent.$('.car_number').attr("value",$(this).data('number'));
		parent.$('.CarId').attr("value",$(this).data('id'));
		if(parent.$('.dispatch-number')){
			parent.$('.dispatch-number').html($(this).data('number'))
		}
		parent.layer.close(index);

	});
	$('.bind').on('click', function() {
		var loadd = layer.load(1, {
		  shade: [0.1,'#fff'] //0.1透明度的白色背景
		});
		var index = parent.layer.getFrameIndex(window.name); 
		var carid=$(this).closest('tr').data('id')
		var driverid=parent.$('.driver_id').val();
		$.ajax({
			method:"POST",
			url:"{:url('driver/bind')}",
			data:{
				driver_id:driverid,
				car_id:carid
			},
			success:function(res){
				layer.close(loadd)
				console.log(res)
				if(res.code==1){
					layer.msg('关联成功');
					window.history.go(0)
				}else{
					layer.msg(res.msg);
				}
			}
		})
//		

	});
	$('.unbind').on('click', function() {
		console.log(window.location.href)
		var loadd = layer.load(1, {
		  shade: [0.1,'#fff'] //0.1透明度的白色背景
		});
		var index = parent.layer.getFrameIndex(window.name); 
		var carid=$(this).closest('tr').data('id')
		var driverid=parent.$('.driver_id').val();
		$.ajax({
			method:"POST",
			url:"{:url('driver/unbind')}",
			data:{
				driver_id:driverid,
				car_id:carid
			},
			success:function(res){
				layer.close(loadd)
				if(res.code==1){
					layer.msg('解除关联成功');
					window.history.go(0)	
				}else{
					layer.msg(res.msg);
				}
			}
		})

	});
})